﻿using System;
using System.Web.Services;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

namespace OrderService
{
    /// <summary>
    /// HY CRM 订单接口
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class OrderService : System.Web.Services.WebService
    {
        private log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        [WebMethod]
        public bool OrderDataValidation(OrderInfo orderinfo, out string msg)
        {
            try
            {
                logger.Info(string.Format("OrderDataValidation Request:{0}", XmlObjectHelper.ObjectToXML(orderinfo)));
                var result = new OrderBLL().VerifyOrderData(orderinfo, out msg);
                logger.Info(string.Format("OrderDataValidation Return:{0}", result));
                return result;
            }
            catch (Exception ex)
            {
                msg = "报单接口验证异常";
                logger.Error("ValidationFailure", ex);
                return false;
            }
        }

        [WebMethod]
        public bool CreateOrder(OrderInfo orderinfo, out string orderID, out string msg)
        {
            try
            {
                logger.Info(string.Format("CreateOrder Request:{0}", XmlObjectHelper.ObjectToXML(orderinfo)));
                var result = new OrderBLL().CreateOrder(orderinfo, out orderID, out msg);
                logger.Info(string.Format("CreateOrder Return:{0},OrderID:{1}", result, orderID));
                return result;
            }
            catch(Exception ex)
            {
                msg = "订单生成异常";
                orderID = string.Empty;
                logger.Error("CreateOrderFailure",ex);
                return false;
            }
        }

        [WebMethod]
        public bool ProcessOrder(string orderid, int empolyeeid, OrderStatus status, bool result, string msg)
        {
            // TODO:记录请求报文
            msg = string.Empty;
            return false;
            // TODO:记录返回报文
        }
    }
}